#!/bin/bash
#this shell scritp is written for the nginx to cut logs by itself,written by ljl(2014-7-16);
#the script should be execute at 00:00 everyday ,you can edit the crontab by a command "crontab -e" as follows;
# 00 00 * * * /bin/bash /usr/local/nginx/nginx-cutlog.sh 
#you should make sure that your nginx logsfile path is "/usr/local/nginx/logs/",or you should edit this shell script by yourself;

logs_path="/usr/local/nginx/logs/"
mkdir -p ${logs_path}$(date -d "yesterday" +"%Y")/$(date -d "yesterday" +"%m")
mv ${logs_path}access.log ${logs_path}$(date -d "yesterday" +"%Y")/$(date -d "yesterday" +"%m")/access.$(date -d "yesterday" +"%Y-%m-%d").log
kill -USR1 `cat /usr/local/nginx/logs/nginx.pid`
#cd ${logs_path}$(date -d "yesterday" +"%Y")/$(date -d "yesterday" +"%m")/
#find . -mtime +2  -exec rm -rf {} \;
